<style lang="scss" >
.container-bg {
  width: 100%;
  background: #fff;
  padding-bottom: 1.5rem;
}
/* 个人信息 */
.info-box {
  height: 164px;
  width: 100%;
  padding: 45px 0px 0 30px;
  background: url("/static/themes/home/home_img_bg@2x.png") center center no-repeat;
  background-size: 100% 100%;
  position: relative;
}

.title-welcome {
  font-size: 17px;
  font-weight: 500;
  color: #222;
}

.title-infoname {
  text-indent: 13px;
  font-size: 14px;
  font-weight: 400;
  color: #222;
}

.title-level-img {
  width: 84px;
  height: 20px;
}

.title-crown {
  width: 55px;
  height: 52px;
  position: absolute;
  right: 11px;
  top: 15px;
}

.title-header-img {
  position: absolute;
  width: 41px;
  height: 41px;
  border-radius: 50%;
  z-index: 10;
  top: 38px;
  right: 30px;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, 1);
}

/* 轮播图 */
.banner-box {
  width: 100%;
  height: 230px;
}

.banner-box img {
  width: 100%;
  height: 100%;
}

/* 快捷按钮 */
.fast-btn-box {
  width: 100%;
  padding: 0px 15px;
  margin: 15px 0 20px;
  background-color: #fff;
}

.fast-btn-box > ul {
  width: 100%;
}
.fast-btn-box li{
  width: 48%;
  float: left;
  box-shadow:0px 3px 9px 0px rgba(187,187,187,0.3);
  border-radius: 5px;
  margin-bottom: .5rem;
  .fast-item-main{
    padding: .5rem;
    overflow: hidden;
    .fast-pic{
      float: left;
      width: 40%;
    }
    .fast-info{
      float: left;
      width: 60%;
    }
    h3{
      color: #121313;
      margin-top: .1rem;
      margin-bottom: .2rem;
      font-weight: 600;
      font-size: .4rem;
      font-family: SourceHanSansCN-Regular;
    }
    p{
      font-weight: 600;
      color: #999999;
    }
  }
}

@media screen and (max-width: 340px){
  .fast-btn-box li .fast-item-main{
    padding: .3rem 0;
  }
}


.fast-btn-box li:nth-child(even){
  margin-left: 4%;
}
.active-banner{
  margin-bottom: .4rem;
}
.fast-btn-box p {
  font-size: 12px;
  font-family: SourceHanSansCN-Regular;
  font-weight: 400;
}

/* 商品列表 */
.goodslist-ul {
  margin-top: 10px;
  padding: 0 0px 60px;
  margin-right: 14px;
}
.goodslist-ul >li {
  width: 50%;
  padding: 0 13px;
  background: #fff;
  margin-bottom: 10px;

}
.goodslist-ul >li > .pro {
  width: 100%;
  min-height: 228px;
  border-radius: 5px;
  border:1px solid rgba(228,228,228,1);
  box-shadow:0px 3px 9px 0px rgba(187,187,187,0.18);
}
.pro > img {
  width: 100%;
  height: 164px;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}
.pro > .pro-sum {
  width: 100%;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  margin-top: 8px;
  padding: 0 5px;
  display: block;
}
.pro-tit {
  width: 100%;
  font-size: 13px;
  font-weight: 500;
  margin-top: 5px;
  padding: 0 5px;
  text-align: center;
  display: block;
  margin-bottom: 5px;
}

.goodslist-li {
  padding: 12px 8px;
  background: #fff;
  height: 170px;
  margin-bottom: 10px;
}

.gooslist-img {
  width: 140px;
  height: 140px;
}

.goodslist-right {
  padding: 15px 10px;
}

.gooslist-sign {
  width: 130px;
  height: 12px;
}

.gooslist-title {
  font-size: 14px;
  font-weight: 400;
}

.gooslist-price {
  font-size: 18px;
  font-weight: bold;
}

.gooslist-btn {
  width: 80px;
  height: 23px;
  font-size: 12px;
  font-weight: 400;
  color: rgba(255, 255, 255, 1);
}

.gooslist-btn img {
  height: 6px;
  height: 11px;
  padding-left: 5px;
}

/* .mint-swipe-indicators {
  position: fixed !important;
  top: 370px !important;
  height: 20px !important;
} */
.line {
  width: 100%;
  height: 10px;
  background: rgba(243, 243, 243, 1);
}
.mT-13 {
  margin-top: 13px
}
.theme-color1 {
  color: #666;
}
.pro-wrap {
  width: 100%;
  height: 48px;
  position: relative;

}
.pro-wrap > img {
  height: 48px;
  display: block;
}


.home-container{
  /*自定义分页器的样式*/
  .swiper-pagination-customs {
    display: inline-block ;
    width: 7px ;
    height: 7px ;
    background:#53DEDB;
    opacity: 0.5;
    margin: 0 5px;
    border-radius: 1rem;
  }
  /*激活时的样式*/
  .swiper-pagination-customs-active {
    opacity: 1;
    width: .4rem;
  }
}
</style>


<style lang="scss" scoped>
  .home-container{
    .mint-swipe {
      width: 95% !important;
      height: 100% !important;
      margin: -115px auto 0px;
      overflow: auto;
      box-shadow: 0px 3px 20px 1px rgba(81, 81, 84, 0.13) !important;
    }

    .mint-swipe-item {
      border: 8px solid #fff;
      box-shadow: 0px 3px 20px 1px rgba(81, 81, 84, 0.13) !important;
    }

    .mint-swipe-indicator {
      width: 6px !important;
      height: 6px !important;
      border-radius: 50% !important;
      background: rgba(104, 201, 242, 1) !important;
      opacity: 0.3;
      border-radius: 50%;
      border: 1px solid rgba(104, 201, 242, 1) !important;
    }

    .mint-swipe-indicator.is-active {
      width: 10px !important;
      height: 5px !important;
      opacity: 1 !important;
      border-radius: 2px !important;
      border: 1px solid rgba(104, 201, 242, 1) !important;
      background: rgba(104, 201, 242, 1) !important;
    }
    .level-box {
      position: relative;
      min-width: 85px;
      height: 20px;
      line-height: 27px;
      display: inline-block;
      background: url("/static/ethel_img/grad.png") center center
        no-repeat;
      background-size: 100% 100%;
      margin-left: 10px;
      font-size: 10px;
      color:#322610;
      text-align: right;
      padding-right: 15px;
    }
    .pos-relative {
      position: relative;
      margin-top: 20px;
    }

    /* 轮播图 */
    .swiper-container {
      width: 100%;
      height: 6.7rem;
      overflow: auto;
      margin: -2.1rem auto 0;
      padding-bottom: 15px;
    }
    /* 单个盒子 */
    .swiper-slide {
      width: 90% ;
      height: 100%;
      box-shadow: 0px 3px 20px 1px rgba(81, 81, 84, 0.13);
    }
    .swiper-wrapper {
      height: 6rem;
    }
    /* 图片样式 */
    .swiper-slide img {
      height: 100%;
      width: 100%;
      margin: 0 auto;
    }
    /*包裹自定义分页器的div的位置等CSS样式*/
    .swiper-pagination-custom {
      position: absolute ;
      bottom: 0px ;
      left: 0 ;
    }

    .swiper-container-3d .swiper-slide-shadow-left {
      background-image: none;
    }
    .swiper-container-3d .swiper-slide-shadow-right {
      background-image: none;
    }
  }
  .container-bg{
    position: relative;
    .home-head-nav{
      position: absolute;
      z-index: 2;
      width: 100%;
      left: 0;
      top: 5px;
      padding: .4rem 14px;
      .hn-search,.hn-serive{
        width: 27px;
        position: relative;
        z-index: 89;
      }
      .hn-search{
        float: left;
      }
      .hn-title{
        width: 1.4rem;
        position: absolute;
        text-align: center;
        top: .1rem;
        left: 50%;
        margin-left: -.7rem;
      }
      .hn-serive{
        float: right;
      }
    }
  }
  .goodslist-head{
    text-align: center;
    font-weight: 600;
    color: #000;
    h3{
      font-weight: 900;
      font-size: .5rem;
      letter-spacing: -2px;
      margin-bottom: .1rem;
    }
    p{
      font-size: .4rem;
      margin-bottom: .5rem;
    }
  }
</style>

<template>
  <div class="container-bg home-container">
    <!-- head菜单按钮 -->
    <div class="home-head-nav">
      <div class="hn-search" @click="routeTo('/NewProList?classId=2')">
        <img class="max" src="/static/themes/home/home_icon_search@2x.png">
      </div>
      <div class="hn-title">
        <img class="max" src="/static/new/home_img_logo@2x.png" alt="">
      </div>
      <div class="hn-serive">
        <img class="max" src="/static/themes/home/home_icon_service@2x.png">
      </div>
    </div>
    <!-- 个人信息 -->
    <div class="info-box flex-display">
    </div>
    <!-- 轮播图 -->
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="(item,index) in bannerImgUl" :key="index">
          <img :src="item.photo" @click="fnOpenProDetail(item.url)">
        </div>
      </div>
      <div class="swiper-pagination"></div>
    </div>
    <!-- 快捷按钮 -->
    <div class="fast-btn-box" v-if="fastBtnData && fastBtnData.length > 0">
      <ul>
        <li
          v-for="(item,index) in fastBtnData"
          :key="index"
          @click="fnGoPage(item.url,item.code)"
        >
        <div class="fast-item-main">
          <div class="fast-pic">
            <img class="max" :src="item.photo">
          </div>
          <div class="fast-info">
            <h3 class="theme-color1">{{item.name}}</h3>
            <p class="theme-color1">{{ item.english_name }}</p>
          </div>

        </div>

        </li>
      </ul>
    </div>

    <!-- 热销商品 -->
    <!-- <SellWell /> -->
    <div class="active-banner">
      <img class="max" src="/static/themes/home/home_banner_sm@2x.png" alt="">
    </div>

    <div class="goodslist-head" v-if="goodslist && goodslist.length > 0">
      <h3>RECOMMEND TO YOU</h3>
      <p>为你推荐</p>
    </div>

    <!-- 商品列表 -->
    <div class="goodslist-box" v-if="goodslist && goodslist.length > 0">
      <ul class="goodslist-ul clearfix">
        <ProductList
          @fnOpenProDetail="fnOpenProDetail"
          v-for="(item, index) in goodslist"
          :key="index"
          :item="item"
        />
      </ul>
    </div>
    <ComFooter/>
  </div>
</template>

<script>
import api from "@/fetch/api";
import ComFooter from "@/common/ComFooter";
import "swiper/dist/css/swiper.css";
import { Toast, Indicator, Swipe, SwipeItem } from "mint-ui";
import SellWell from "./components/SellWell";
import ProductList from "@/common/ProductList";
import { mapGetters } from "vuex";
import {} from "mint-ui";

export default {
  name: "home",
  data() {
    return {
      // 昵称
      nickname: "",
      // 轮播图数据
      bannerImgUl: [],
      // 功能区数据
      fastBtnData: [],
      // 商品列表
      goodslist: [],
      currentIndex: 1 // 默认第一张
    };
  },
  created() {
    this.ethelWxUserInfo = this.getlocalStorage(this.companyUnique)
      ? this.getlocalStorage(this.companyUnique)
      : "";
    // 获取功能区数据
    this.fnGetRegionList();
    // 获取首页banner数据
    this.fnGetBannerList();
    // 获取商品列表数据
    if (this.ethelWxUserInfo) {
      this.getProductList();
    }
  },
  methods: {
    initSwiper() {
      // 轮播图
      var _this = this
      new Swiper(".swiper-container", {
        loop: true,
        effect: "coverflow",
        grabCursor: true,
        centeredSlides: true,
        slidesPerView: "auto",
        coverflowEffect: {
          rotate: 40,
          stretch: 0,
          depth: 100,
          modifier: 1,
          slideShadows: true
        },
        // 如果需要分页器
        pagination: {
          el: ".swiper-pagination",
          type: "custom",
          Clickable: "true",
          renderCustom: function(swiper, current, total) {
            var customPaginationHtml = "";
            _this.currentIndex = current - 1
            for (var i = 0; i < total; i++) {
              //判断哪个分页器此刻应该被激活
              if (i == current - 1) {
                customPaginationHtml +=
                  '<span class="swiper-pagination-customs swiper-pagination-customs-active"></span>';
              } else {
                customPaginationHtml +=
                  '<span class="swiper-pagination-customs"></span>';
              }
            }
            return customPaginationHtml;
          }
        },
        autoplay: {
          delay: 3000, //切换时间，默认三秒
          stopOnLastSlide: false, //默认false，如为true，到最后停止切换
          disableOnInteraction: false, //人为滑动后，是否停止，默认停止true
          waitForTransition: true
        }
      });
    },
    /**
     * @author yang
     * @desc 获取商品列表
     */

    getProductList() {
      api
        .getProductList({
          uid: this.ethelWxUserInfo.id
        })
        .catch(result => {
          console.warn(result);
          if (result.status === 200 && result.data.code === 0) {
            this.goodslist = result.data.data;
          }
        });
    },

    fnGetRegionList() {
      api.getRegion({}).catch(result => {
        console.log(result);
        if (result.status == 200 && result.data.code === 0) {
          result.data.data.forEach(item => {
            switch (parseInt(item.code)) {
              case 1:
                item.url = "number";
                break;
              case 2:
                item.url = "NewTeam";
                break;
              case 3:
                item.url = "NewOrder";
                break;
              case 4:
                item.url = "/modules/moneybag";
                break;
              case 6:
                item.url = "pingtuan";
                break;
              case 7:
                item.url = "/new/checkin";
                break;
              case 8:
                item.url = "/new/freeGet";
                break;
              // case 10:
              //   item.url = "/new/freeGet";
              //   break;
              // case 11:
              //   item.url = "/new/freeGet";
              //   break;
              default:
                item.url = "NewWelfare";
            }
          });
          this.fastBtnData = result.data.data;
        }
        console.log("功能区");
        console.log(this.fastBtnData);
      });
    },
    fnGetBannerList() {
      api.getBanner({}).catch(result => {
        console.log(result);
        console.log("banner数据");
        if (result.status == 200 && result.data.code === 0) {
          this.bannerImgUl = result.data.data;
          setTimeout(() => {
            this.initSwiper();
          }, 10);
        }
      });
    },
    /**
     * @author yang
     * @desc 跳转到相应的页面
     * @param {String} _url 路由地址
     */
    fnGoPage(_url, _code) {
      if(_code == '8'){
        this.$router.push('/NewProList?classId=5');
      }else if (_code == '10') {
        this.$router.push('/NewProList?classId=6');
      }else if (_code == '11') {
        this.$router.push('/NewProList?classId=7');
      }else if (_code == '7') {
        this.$router.push('/NewProList?classId=8');
      }
    },
    fnToGoodslistDetail(_id) {
      console.log(_id);
      this.$router.push({
        path: "/goodslist_detail",
        query: {
          id: _id
        }
      });
    }
  },
  watch: {
      userInfoExist(val) {
        if(val) {
          this.ethelWxUserInfo = this.getlocalStorage(this.companyUnique);
          this.getProductList()
        }
      }
    },
  computed: {
    ...mapGetters(["userInfo", "userInfoExist"])
  },
  components: {
    Toast,
    Indicator,
    ComFooter,
    Swipe,
    SwipeItem,
    ProductList,
    SellWell,
  }
};
</script>
